<%@page  pageEncoding="UTF-8" contentType="text/json;charset=UTF-8"
         import="java.io.*,java.util.*,java.net.*" %><%
request.setCharacterEncoding("UTF-8");
System.out.println("METHOD="+request.getMethod());

String prefix="http://portal-mngt.gmcc.net:8080";
String serverName=request.getServerName();
if(serverName.startsWith("tpac")){
    prefix="http://tpac-app.gmcc.net";
}
else if(serverName.startsWith("pac")){
    prefix="http://pac-app.gmcc.net";
}//if

String cookieName="iPlanetDirectoryPro";
String cookieVal=null;

 javax.servlet.http.Cookie[] cks=request.getCookies();
  for(int i=0; i<cks.length; i++){
              if(cks[i].getName().equals(cookieName)){
                  cookieVal = cks[i].getValue();
                  break;
              }
 }//for

String desktopName = request.getParameter("id");

if(request.getMethod().equalsIgnoreCase("GET")){
        //读取定制树
        
        String classid = request.getParameter("classid");
        

        String queryStr="";

        if(classid!=null && classid.length()>0){
                queryStr = "?classid=" + URLEncoder.encode(classid,"UTF-8");
            }//if

         URL url = new URL(prefix+"/smc/treeModel/customTree/"+desktopName+queryStr);

          HttpURLConnection huc = (HttpURLConnection) url.openConnection();

         com.sonalb.net.http.cookie.Client client = new com.sonalb.net.http.cookie.Client();

         huc.setRequestProperty("Cookie","iPlanetDirectoryPro="+cookieVal);

          huc.connect();

          InputStream is=huc.getInputStream();

          InputStreamReader isr = new InputStreamReader(is,"UTF-8");

          BufferedReader br = new BufferedReader(isr);

          for(String line; (line=br.readLine())!=null; ){
              out.println(line);
          }

          br.close();
          isr.close();
          is.close();

          huc.disconnect();

}
else {
        URL url = new URL(prefix+"/smc/desktopPreview/customLayout/"+desktopName);

          HttpURLConnection huc = (HttpURLConnection) url.openConnection();
          huc.setRequestProperty("Content-Type","text/json");
          huc.setRequestMethod("POST");
          huc.setDoOutput(true);
          huc.setDoInput(true);
          huc.setRequestProperty("Cookie","iPlanetDirectoryPro="+cookieVal);
         

          
          //huc.connect();

          BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));

          OutputStream os=huc.getOutputStream();
          PrintWriter pw=new PrintWriter(os);

          for(String line; (line=br.readLine())!=null; ){
              pw.println(line);
          }//for

          pw.close();
          os.close();
          br.close();

          InputStream is=huc.getInputStream();

          InputStreamReader isr = new InputStreamReader(is,"UTF-8");

          br = new BufferedReader(isr);

          for(String line; (line=br.readLine())!=null; ){
              out.println(line);
          }

          br.close();
          is.close();
          
          huc.disconnect();


}
%>